package com.feixiang.feixiangpicturebackend.model.enums;
import cn.hutool.core.util.ObjUtil;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;

/**
 * 图片审核状态枚举
 */
@Getter
public enum PictureReviewStatusEnum {
    REVIEWING("待审核", 0),
    PASS("通过", 1),
    REJECT("拒绝", 2);

    private final String text;
    private final int value;

    PictureReviewStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }
    /**
     * 根据 value 获取枚举
     * @param value
     * @return
     */
    public static PictureReviewStatusEnum getEnumByValue(Integer value) {
       if(ObjUtil.isEmpty(value)){
           return null;
       }
       for (PictureReviewStatusEnum pictureReviewStatusEnum : PictureReviewStatusEnum.values()) {
           if (pictureReviewStatusEnum.value == value) {
               return pictureReviewStatusEnum;
           }
       }
       return null;
   }
   //这样for比较慢，把枚举值放到map中，key为value，value为枚举对象，这样就可以直接根据value获取枚举对象了
   private static final Map<Integer, PictureReviewStatusEnum> MAP = new HashMap<>();
    static {
        for (PictureReviewStatusEnum value : PictureReviewStatusEnum.values()) {
            MAP.put(value.value, value);
        }
    }
}
